using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace App
{
    public class CTab : TabPage
    {
        public CTab()
        {
            this.SetStyle(ControlStyles.UserPaint, true);
            //this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            //this.SetStyle(ControlStyles.ResizeRedraw, true);
            //this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.Padding = new System.Windows.Forms.Padding(30);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;

            switch (Common.Theme)
            {
                case Common.ColorScheme.Blue:
                    {
                        e.Graphics.Clear(Common.Blue);

                        Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

                        Color[] col = new Color[] { Color.FromArgb(225, 234, 245), Color.FromArgb(209, 223, 240), 
                            Color.FromArgb(199, 216, 237), Color.FromArgb(231, 242, 255) };
                        float[] pos = new float[] { 0.0f, 0.1f, 0.2f, 1.0f };

                        LinearGradientBrush brush = DrawHelper.GetBrush(col, pos, rect);
                        DrawHelper.FillRoundRectangle(e.Graphics, brush, rect, 3f);
                        DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(Color.FromArgb(141, 178, 227)), rect, 3f);
                        rect.Offset(1, 1);
                        rect.Width -= 2;
                        rect.Height -= 2;
                        using (LinearGradientBrush b = new LinearGradientBrush(rect, Color.FromArgb(231, 239, 248), Color.Transparent, LinearGradientMode.ForwardDiagonal))
                        {
                            DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(b), rect, 3f);
                        }
                        brush.Dispose();
                    }
                    break;
                case Common.ColorScheme.Custom:
                    {
                        e.Graphics.Clear(Common.Color);

                        Rectangle rect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

                        Color[] col = new Color[] { DrawHelper.GetColor(1.025,Common.Color), DrawHelper.GetColor(1.0,Common.Color), 
                            DrawHelper.GetColor(0.975,Common.Color), DrawHelper.GetColor(1.075,Common.Color) };
                        float[] pos = new float[] { 0.0f, 0.1f, 0.2f, 1.0f };

                        LinearGradientBrush brush = DrawHelper.GetBrush(col, pos, rect);
                        DrawHelper.FillRoundRectangle(e.Graphics, brush, rect, 3f);
                        DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(DrawHelper.GetColor(0.75, Common.Color)), rect, 3f);
                        rect.Offset(1, 1);
                        rect.Width -= 2;
                        rect.Height -= 2;
                        DrawHelper.DrawRoundRectangle(e.Graphics, new Pen(new LinearGradientBrush(rect,
                            DrawHelper.GetColor(1.05, Common.Color), Color.Transparent, LinearGradientMode.ForwardDiagonal)), rect, 3f);
                    }
                    break;
            }
        }
    }
}